import React from 'react';
import 'antd/dist/antd.min.css';
import { Table, Button } from 'antd';
import { DownloadOutlined } from '@ant-design/icons';
class ListInfo extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      data: []
    };
  }
  componentDidMount() {
    this.props.axios.post("/list", { address: this.props.address }).then(res => {
      // console.log(res.data);
      this.setState({ data: [res.data] });
    })
  }
  render() {
    console.log(this.state.data);
    return (<div>
      <Table dataSource={this.state.data} rowKey="address" columns={[
        {
          title: 'eth地址',
          dataIndex: 'address',
        }, {
          title: '用户名',
          dataIndex: 'username',
        }, {
          title: '性别',
          dataIndex: 'sex',
        }, {
          title: '电话',
          dataIndex: 'phoneNum',
        }, {
          title: 'salt种子',
          dataIndex: 'salt_seed',
        }, {
          title: 'merkle_root',
          dataIndex: 'merkle_root',
        }, {
          title: 'merkle_root_signature',
          dataIndex: 'merkle_root_signature',
        },
        {
          title: '下载',
          dataIndex: 'download',
          render: (text, record) => (
            <Button type="primary" icon={<DownloadOutlined onClick={() => {
              // console.log(text);
              console.log(record);
              const url = window.URL.createObjectURL(new Blob([JSON.stringify(record)]));
              const link = document.createElement('a'); //创建a标签
              link.style.display = 'none';
              link.href = url; // 设置a标签路径
              link.download = record.address + '.json'; //设置文件名， 也可以这种写法 （link.setAttribute('download', '名单列表.xls');
              document.body.appendChild(link);
              link.click();
              URL.revokeObjectURL(link.href); // 释放 URL对象
              document.body.removeChild(link);
            }} />} />
          )
        }
      ]} />
    </div>);
  }
}
export default ListInfo;